import './css/toast.less';

export const Toast = function (text,placement, className, timeout, options) {

    //如果已经弹出一个了，那么就先移除，这边只会有一个

    try {
        document.body.removeChild(document.querySelector('div.toast-it'));
    } catch (e) {

    }
    //开始创造
    timeout = timeout || 2000;
    let toast = document.createElement('DIV');
    toast.classList.add('toast-it');
    toast.classList.add('alert');
    toast.classList.add(className || 'alert-success');
    placement = placement || 'toast-right'
    toast.classList.add(placement);
    let content = document.createTextNode(text);
    toast.appendChild(content);
    toast.style.animationDuration = timeout / 1000 + 's';

    for (let prop in options) {
        toast.style[prop] = options[prop];
    }
    //别被挡住了
    toast.style['z-index'] = 9999999;
    document.body.appendChild(toast);
    setTimeout(function () {
      try {
          document.body.removeChild(toast);
      } catch (e) {

      }
    }, timeout);
};
